package com.ruoyi.business.acc.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.acc.domain.Acc;
import com.ruoyi.business.acc.service.IAccService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 账户Controller
 *
 * @author zengxiangjiang
 * @date 2022-03-15
 */
@Controller
@RequestMapping("/acc/inf")
public class AccController extends BaseController
{
    private String prefix = "acc/inf";

    @Autowired
    private IAccService accService;

    @RequiresPermissions("acc:inf:view")
    @GetMapping()
    public String inf()
    {
        return prefix + "/inf";
    }

    /**
     * 查询账户列表
     */
    @RequiresPermissions("acc:inf:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Acc acc)
    {
        startPage();
        List<Acc> list = accService.selectAccList(acc);
        return getDataTable(list);
    }

    /**
     * 导出账户列表
     */
    @RequiresPermissions("acc:inf:export")
    @Log(title = "账户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Acc acc)
    {
        List<Acc> list = accService.selectAccList(acc);
        ExcelUtil<Acc> util = new ExcelUtil<Acc>(Acc.class);
        return util.exportExcel(list, "账户数据");
    }

    /**
     * 新增账户
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存账户
     */
    @RequiresPermissions("acc:inf:add")
    @Log(title = "账户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Acc acc)
    {
        return toAjax(accService.insertAcc(acc));
    }

    /**
     * 修改账户
     */
    @RequiresPermissions("acc:inf:edit")
    @GetMapping("/edit/{merId}")
    public String edit(@PathVariable("merId") String merId, ModelMap mmap)
    {
        Acc acc = accService.selectAccByMerId(merId);
        mmap.put("acc", acc);
        return prefix + "/edit";
    }

    /**
     * 修改保存账户
     */
    @RequiresPermissions("acc:inf:edit")
    @Log(title = "账户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Acc acc)
    {
        return toAjax(accService.updateAcc(acc));
    }

    /**
     * 删除账户
     */
    @RequiresPermissions("acc:inf:remove")
    @Log(title = "账户", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(accService.deleteAccByMerIds(ids));
    }
}
